//
//  RadioButtonHelper.swift
//  Employee
//
//  Created by swordjoy on 2017/3/31.
//  Copyright © 2017年 remotevillage. All rights reserved.
//

import Foundation

struct RadioButtonHelper {
  
  var selectIndex: Int {
    didSet {
      
      if buttons[selectIndex].isSelected == true {
        buttons[selectIndex].isSelected = false
        return
      }
      
      for button in buttons {
        button.isSelected = false
      }
      
      buttons[selectIndex].isSelected = true
      
    }
  }
  
  var hasSelected: Bool {
    
    for button in buttons {
      if button.isSelected {
        return true
      }
    }
    
    return false
    
  }
  
  var buttons: [UIButton] = []
  
  // 默认选择
//  init(radioButtons: [UIButton], defaultSelectIndex: Int = 0) {
//    self.buttons = radioButtons
//    self.selectIndex = 0
//    self.buttons[selectIndex].isSelected = true
//  }
  
  // 不默认选择
  init(radioButtons: [UIButton]) {
    self.buttons = radioButtons
    self.selectIndex = -1
  }
  
}
